//
// Created by zy-li14 on 16-9-24.
//

#ifndef AI9_LOGIC_2017_GAME_H
#define AI9_LOGIC_2017_GAME_H
#include "../sdk/const.h"
#include "entity.h"
#include "skill.h"
#include "entitymanager.h"
#include <tuple>
#include <queue>
#include <sdk/PlayerInfo.h>
#include "include/sdk/Commands.h"
#include "Entities/linkmanager.h"
#include "Terrain.h"
#include "json/json.h"

class Game {
public:
    static constexpr int TIE = -2;
    static constexpr int UNFINISHED = -1;
    int round_count;
    int nowRound;//当前回合数
    std::vector<Json::Value> replay_data;

    explicit Game ();
    explicit Game (const Game&) = delete;
    Game& operator= (const Game&) = delete;
    explicit  Game (Game&&) = default;
    Game&operator= (Game&&) = default;

    void init ();//创建新Game时的初始化
    void setupBattleGround();
    void initPlant();
    void roundPreparation (const Commands& cmd);//回合开始阶段
    void run();
    void oneRoundRun();//运行一回合
    void roundClean ();//回合结束之后的处理
    int getWinner () const;//若不存在胜利者，则返回-1,若已经是最后一回合，则要强制返回胜利者，若平局则返回-1
    void writeReplay();
    Json::Value getReplay();
    void dumpReplay(std::string filename);
    PlayerInfo getPlayerInfo(int playerId) const;//返回玩家的信息
    int getWinnerFinal() const;

    EntityManager entityManager;
    entity::EnergyManager* linkManager;
    Terrain terrain;//地形参数
    typedef std::tuple<Entity*, std::string, std::vector<std::string> > EntitySkillCall;
    std::map<int, std::queue<EntitySkillCall> > SkillCallQueue;
    std::vector<std::tuple<std::string, std::string, std::vector<std::string> > > PerformedSkills;
};


#endif //AI9_LOGIC_2017_GAME_H
